package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TTaskOrder;
import com.ruoyi.system.service.ITTaskOrderService;
import com.ruoyi.framework.web.base.BaseController;
import com.ruoyi.common.page.TableDataInfo;
import com.ruoyi.common.base.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 工单 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-02-20
 */
@Controller
@RequestMapping("/system/tTaskOrder")
public class TTaskOrderController extends BaseController
{
    private String prefix = "system/tTaskOrder";
	
	@Autowired
	private ITTaskOrderService tTaskOrderService;
	
	@RequiresPermissions("system:tTaskOrder:view")
	@GetMapping()
	public String tTaskOrder()
	{
	    return prefix + "/tTaskOrder";
	}
	
	/**
	 * 查询工单列表
	 */
	@RequiresPermissions("system:tTaskOrder:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(TTaskOrder tTaskOrder)
	{
		startPage();
        List<TTaskOrder> list = tTaskOrderService.selectTTaskOrderList(tTaskOrder);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出工单列表
	 */
	@RequiresPermissions("system:tTaskOrder:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TTaskOrder tTaskOrder)
    {
    	List<TTaskOrder> list = tTaskOrderService.selectTTaskOrderList(tTaskOrder);
        ExcelUtil<TTaskOrder> util = new ExcelUtil<TTaskOrder>(TTaskOrder.class);
        return util.exportExcel(list, "tTaskOrder");
    }
	
	/**
	 * 新增工单
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存工单
	 */
	@RequiresPermissions("system:tTaskOrder:add")
	@Log(title = "工单", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(TTaskOrder tTaskOrder)
	{		
		return toAjax(tTaskOrderService.insertTTaskOrder(tTaskOrder));
	}

	/**
	 * 修改工单
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") String id, ModelMap mmap)
	{
		TTaskOrder tTaskOrder = tTaskOrderService.selectTTaskOrderById(id);
		mmap.put("tTaskOrder", tTaskOrder);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存工单
	 */
	@RequiresPermissions("system:tTaskOrder:edit")
	@Log(title = "工单", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(TTaskOrder tTaskOrder)
	{		
		return toAjax(tTaskOrderService.updateTTaskOrder(tTaskOrder));
	}
	
	/**
	 * 删除工单
	 */
	@RequiresPermissions("system:tTaskOrder:remove")
	@Log(title = "工单", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(tTaskOrderService.deleteTTaskOrderByIds(ids));
	}
	
}
